<?php
namespace app\api\controller;

use app\api\controller;
use think\Db;


class index extends Base
{   
     
 
    public function init(){
        $Force     = model('Force');
        $Redpacket = model('Redpacket');

        $data['force_info'] = $Force->getUserForceInfo($this->userId);
        
        if($daily_redpacket_price = $Redpacket->addDailyRedpacket($this->userId)){
        	$data['daily_redpacket_price'] = $daily_redpacket_price;
        }
           
        $this->success("请求成功!", $data);

     }

    
    //获取验证码的操作
    public function getVerifity(){

    	$data = $this->request->param();
 
        if($verify = model('User')->getVerifity($data['mobile']))
             $this->success('获取验证码成功',['verify' =>$verify]);
  
    }

     //绑定手机号
    public function bindMobile(){
        $Redpacket = model('redpacket');

        $data = $this->request->param();
        
        $mobile = $data['mobile'];
        $current_time = time();

        if(Db::name('user')->where('id',$this->userId)->update(['mobile'=>$mobile,'mobile_binding_time'=>$current_time])){
            //为用户发放红包
            $Redpacket->giveUserRedpacket($this->userId,1,4.9);
            $this->success('绑定成功！');
        }
    }

     


}
